package com.binguo.wxapi.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.binguo.common.util.UrlUtils;
import com.binguo.model.model.SideBoard;
import org.apache.http.ParseException;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.HashMap;

import java.util.Map;

@Service
public class AiyouweiUtils {

    private static int AppId = 66468;

    private static String DeviceId = "b5yp1yslhiVvoWTLq1Lc";

    private  String Timestamp = System.currentTimeMillis()+"";


    /**
     *
     * @param cellNo 可同时开启多个柜号
     * @param commandCode
     * @param sideBoard
     * @return
     * @throws ParseException
     * @throws IOException
     */
    public String runCommand(String[] cellNo, String commandCode,SideBoard sideBoard) throws ParseException, IOException {
        Map<String,Object> map = new HashMap<>();
        //map.put("AppId",sideBoard.getAppid().toString());
        map.put("AppId",AppId);
        map.put("DeviceId",sideBoard.getDeviceId());
        map.put("Timestamp",Timestamp);
        map.put("Digest","");
        map.put("CellNos",cellNo);
        map.put("CommandCode",commandCode);
        String json = JSON.toJSONString(map);
        JSONObject jsonObject = JSON.parseObject(json);
        return UrlUtils.send("http://openapi.58auv.com/api/open/runcommand",jsonObject,"utf-8");
    }


    public String querryAll(SideBoard sideBoard)throws ParseException, IOException {
        Map<String,String> map = new HashMap<>();
        map.put("AppId",sideBoard.getAppid().toString());
        map.put("DeviceId",sideBoard.getDeviceId());
        map.put("Timestamp",Timestamp);
        map.put("Digest","");
        String json = JSON.toJSONString(map);
        JSONObject jsonObject = JSON.parseObject(json);
        return UrlUtils.send("http://openapi.58auv.com/api/open/query/all",jsonObject,"utf-8");
    }



    public String querry(Integer cellNo)throws  ParseException, IOException  {
        Map<String,String> map = new HashMap<>();
        map.put("AppId",AppId+"");
        map.put("DeviceId",DeviceId);
        map.put("Timestamp",Timestamp);
        map.put("Digest","");
        map.put("CellNos",""+cellNo);
        String json = JSON.toJSONString(map);
        JSONObject jsonObject = JSON.parseObject(json);

        return UrlUtils.send("http://openapi.58auv.com/api/open/query",jsonObject,"utf-8");
    }
}
